package com.webdemo11.util;
import org.hibernate.SessionFactory;
import org.springframework.web.context.ContextLoader;
import org.springframework.web.context.WebApplicationContext;


public class SpringHandler {
	private static WebApplicationContext applicationContext;

	static{
		applicationContext = ContextLoader.getCurrentWebApplicationContext();
	}
	public static WebApplicationContext getApplicationContext() {
		return applicationContext;
	}
	/**
	 * 统计二级缓存命中率
	 */
	public static void showStatistics(){
		SessionFactory sessionFactory = (SessionFactory) applicationContext.getBean("sessionFactory");
		long hit = sessionFactory.getStatistics().getSecondLevelCacheHitCount();
		long miss = sessionFactory.getStatistics().getSecondLevelCacheMissCount();
		long put = sessionFactory.getStatistics().getSecondLevelCachePutCount();
		System.out.println("hit:"+hit+" "+"miss:"+miss+" "+"put:"+put);
	}
}
